#include "graph.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 220;

int b[N], c[N], p[N], dep, cnt, dis[N][N];

void dfs(int u) {
    // if (u > 10) exit(0);
    // cout << "u = " << u << " now = " << now << " " << dep << endl;
    int d = NumberOfRoads();
    int a[N];
    for (int i = 1; i <= d; i++)
        a[i] = i;
    random_shuffle(a + 1, a + d + 1);
    int num = 0;
    for (int i = 1; i <= d; i++) {
        Move(a[i], 2);
        int lst = LastRoad();
        if (Color() == 2) {
            Move(lst, 3); num++;
        } else {
            Move(lst, 1);
        }
    }
    for (int i = dep - 1; i >= 1; i--) {
        if (num == 0) break;
        Move(c[i + 1], 2);
        // cout << "qwq now = " << now << endl;
        if (Color() == 3) {
            dis[u][p[i]] = dis[p[i]][u] = 1;
            num--;
            // cout << "qwq" << endl;
            if (num == 0) {
                // cout << "qwq" << endl;
                // cout << "now = " << now << endl;
                for (int j = i + 1; j <= dep; j++)
                    Move(b[j], 2);
                // cout << "qwq" << endl;
                break;
            }
        }
    }
    for (int i = 1; i <= d; i++) {
        b[++dep] = a[i];
        // cout << "qwq2 " << a[i] << " " << d << " " << now << endl;
        Move(a[i], 2);
        c[dep] = LastRoad();
        // cout << "lst = " << now << " " << g[now][lst]
        if (Color() == 2) {
            // cout << "qwq3 " << now << endl;
            dep--; Move(c[dep], 2); continue;
        }
        // cout << "qwqwq" << endl;
        // cout << "Color = " << Color() << " c = " << c[dep] << endl;
        p[dep] = ++cnt;
        dfs(p[dep]);
        Move(c[dep], 3);
    }
}

void Inspect(int R) {
    memset(dis, -245, sizeof(dis));
    p[++dep] = ++cnt; dfs(1);
    for (int k = 1; k <= cnt; k++)
        for (int i = 1; i <= cnt; i++)
            for  (int j = 1; j <= cnt; j++)
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
    for (int i = 1; i <= R; i++) {
        int num = 0;
        for (int j = 1; j <= cnt; j++)
            for (int k = j + 1; k <= cnt; k++)
                if (dis[j][k] == i) num++;
        cout << num << endl;
    }
    // for (int i = 1; i <= cnt; i++)
    //     for (int j = 1; j <= cnt; j++)
            // cout << "i = " << i << " j = " << j << " dis = " << dis[i][j] << endl;
}
